package cn.echogo.framework.app;

import java.util.List;

import android.os.Bundle;
import android.widget.Toast;
import cn.echogo.demo.model.XID;
import cn.echogo.framework.activity.EGActivity;
import cn.echogo.framework.core.AsyncExecuteCallback;
import cn.echogo.framework.core.ResponseEntity;
import cn.echogo.framework.core.Sp;
import cn.echogo.framework.core.Support;
import cn.echogo.ipart.R;

@Support({ Sp.asyncExecutor, Sp.viewHelper, Sp.httpInvoker })
public class DemoActivity extends EGActivity implements AsyncExecuteCallback {

	private LadyManager ladyManager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.demo_http_test);
		
		ladyManager = LadyManager.newInstance(httpInvoker);

		Bundle params = new Bundle();
		params.putInt("pageIndex", 1);
		params.putInt("pageSize", 20);
		params.putString("country", "China");
		asyncExecutor.submit(XID.QUERY_USER, params);
		viewHelper.showProgressBar(R.id.container, 201);

	}

	@Override
	public void onExecute(int id, Bundle params) throws Exception {
		Thread.sleep(3000);
		// ResponseEntity<List<UserBean>> re =
		// httpInvoker.post("http://xxx.xxx.xxx", null, XType.USER_LIST());
		ResponseEntity<List<Object>> re = ladyManager.queryLadyList(1, 10);
		// asyncExecutor.publishResult(id, re);
	}

	@Override
	public void onPostExecute(int id, Bundle result) {
		viewHelper.hideProgressBar(R.id.container, 201);
		viewHelper.showTipText(R.id.container, 202, "No Data.");
		Toast.makeText(this, "country = " + result.getString("country"), Toast.LENGTH_LONG).show();
	}

	@Override
	public void onException(int id, Bundle params, Exception e) {
		viewHelper.hideProgressBar(R.id.container, 201);
		e.printStackTrace();
	}

	@Override
	protected void onDestroy() {
		asyncExecutor.cancel(XID.QUERY_USER);
		super.onDestroy();

	}

}
